<template>
  <!-- 搜索用户 -->
  <div id="searchUser">
    <van-list v-model="loading"
              :finished="finished"
              finished-text="没有更多了"
              offset="5"
              @load="onLoad">
      <van-cell-group>
        <van-cell center
                  v-for="(user,index) in userList"
                  :key="index"
                  :title="user.nickname">
          <template #icon>
            <van-image round
                       width="40"
                       height="40"
                       :src="user.avatarUrl"
                       style="padding-right:10px" />
          </template>
          <template #label>
            <div class="van-ellipsis">
              <span style="font-size: 12px">{{user.signature.length>=18?user.signature.slice(0,18)+' ...':user.signature}}</span>
            </div>

          </template>
          <template #right-icon>
            <van-button round
                        plain
                        size="mini"
                        icon="plus"
                        :color="globalObj.normColor">关注</van-button>
          </template>
        </van-cell>
      </van-cell-group>
    </van-list>
  </div>
</template>

<script>
import { getSearch } from '@/api/search'
export default {
  name: 'searchUser',
  data() {
    return {
      loading: true,
      finished: false,
      limit: 20,
      type: 1002,
      userList: [],
    }
  },
  methods: {
    onLoad() {
      this.loading = true
      this.limit = this.limit + 10
      getSearch(this.rowText, this.limit, this.type).then((res) => {
        this.userList = res.result.userprofiles
        if (res.code == 400) {
          this.finished = true
        }
        this.loading = false
      })
    },
    initData() {
      getSearch(this.rowText, this.limit, this.type).then((res) => {
        this.userList = res.result.userprofiles
        this.loading = false
      })
    },
  },
  created() {
    this.initData()
  },
}
</script>

<style>
</style>